﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UIT_CV_Management
{
    public partial class UserControlMonThiTotNghiep : UserControl
    {
        private Boolean isEveryOK = false;
        private Boolean isTenMonThiOK = false;
        private Boolean isKetQuaThiOK = false;

        public String TenMonThi
        {
            get
            {
                return txbTenMonThi.Text;
            }
            set
            {
                TenMonThi = value;
            }
        }
        public float DiemThi
        {
            get
            {
                return (float.Parse(txbDiem.Text));
            }
            set
            {
                DiemThi = value;
            }
        }

        public UserControlMonThiTotNghiep()
        {
            InitializeComponent();

            this.hideAllErrorImage();
        }

        private void hideAllErrorImage()
        {
            pictureBoxMonThi.Visible = false;
        }
        private void txbTenMonThi_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbTenMonThi.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isTenMonThiOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbTenMonThi.BackColor = Color.Tomato;
                pictureBoxMonThi.Visible = false;
            }
            else
            {
                isTenMonThiOK = true;
                txbTenMonThi.BackColor = Color.White;
                pictureBoxMonThi.Visible = true;
            }
        }

        private void txbDiem_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;
            float result;
            if (float.TryParse(txbDiem.Text, out result) == false)
            {
                isHasError = true;
            }
            else
                if ((result < 0) || (result > 10))
                {
                    isHasError = true;
                }

            if (isHasError)
            {
                isKetQuaThiOK = false;

                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbDiem.BackColor = Color.Tomato;
                pictureBoxMonThi.Visible = false;
            }
            else
            {
                isKetQuaThiOK = true;
                txbDiem.BackColor = Color.White;
                pictureBoxMonThi.Visible = true;
            }
        }

        public Boolean isMonThiOK()
        {
            //Validate
            txbTenMonThi_Validating(txbTenMonThi, null);
            txbDiem_Validating(txbDiem, null);

            if (isTenMonThiOK && isKetQuaThiOK)
                isEveryOK = true;
            else
                isEveryOK = false;
            return isEveryOK;
        }
    }
}
